# coding=utf8

class Preliminary:

    @staticmethod
    def if_statement(a=10):
        if a > 10:
            if a > 1000:
                print("{} is too big!".format(a))
            elif a > 500:
                print("{} is much bigger than 10!".format(a))
            else:
                print("{} is bigger than 10".format(a))
        else:
            print("{} is less than 10!".format(a))

        if 1 == 1.0:
            print("1 == 1.0")

        # 浮点数的有效位数是二进制53位，换算位十进制则为16位
        if 2 == 2.0000000000000000001:    # 超过14个0，1是无效的
            print('2 == 2.00...0(16)1')
        # 如果小数点之前有一位数字，小数点后面的15位之后的数字是无效的
        if 2 < 2.000000000000001:         # 14个0时，1是有效的
            print('2 < 2.0...0(14)1')

    @staticmethod
    def while_statement():
        # while exp1
        lp = 1
        while lp < 10:
            print(lp, end=' ')
            lp += 1
        print("")

        # continue，不执行其余语句
        lp = 1
        while lp < 10:
            print(lp, end=' ')
            if lp == 5:
                lp += 2
                continue
            lp += 1
        else:
            print("else")

        # break退出，不执行else
        lp = 1
        while lp < 10:
            print(lp, end=' ')
            if lp == 5:
                break
            lp += 1
        else:
            print("else")
        print("")

        # 出现异常退出，仍然执行else
        a = 3
        while a >= 0:
            a -= 1
            try:
                print(f"a = {a}, 10/a = {10/a}")
            except ZeroDivisionError as e:
                print(e)
        else:
            print(f"a = {a}")

    @staticmethod
    def for_statement():
        for c in "abc":
            print(c, end='/')
        print("")

        for v in [1, 3, 5]:
            print(v, end='')

        print("")

        for v, c in [(1, 'a'), (2, 'b')]:
            print(v**2, c.upper())
        else:
            print('end')

        for c in "abc":
            if c == 'b':
                continue
            print(c, end='')
        else:
            print("")
            print("for-loop end")

        for c in "abc":
            if c == 'b':
                break
            print(c, end='')
        else:
            print("for-loop end")
        print("")

    @staticmethod
    def with_stat():
        with open('myfile.txt', 'wt') as fh:
            fh.writelines("line1\nlien2")

        with open('myfile.txt', mode='rt') as fh:
            for line in fh.readlines():
                print(line, end='')


def task():
    score_list = [77, 65, 35, 80, 55, 48, 66, 90, 53, 91]
    score_greater_60 = []
    score_less_60 = []
    for score in score_list:
        if score >= 60:
            score_greater_60.append(score)
        else:
            score_less_60.append(score)
    else:
        print(score_greater_60)
        with open('score21.txt', 'wt') as fh:
            for score in score_less_60:
                fh.write(str(score)+'\n')


if __name__ == '__main__':
    # Preliminary.if_statement(5)
    Preliminary.while_statement()
    # Preliminary.with_stat()
    # Preliminary.for_statement()
    # task()
